package org.common.base;

import java.io.Serializable;
import java.util.UUID;

/**
 *
 * @author gus
 */
public class UniqueID implements Serializable
{
    private static final long serialVersionUID = 5479705127643593534L;
    
    private UUID value;  
    private static UUID  EMPTY_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
    
    public static UniqueID Empty = new UniqueID(EMPTY_UUID);
        
    public UniqueID(UUID id)
    {
        this.value = UUID.fromString(id.toString());
    }

    public UniqueID(String id)
    {
        this.value = UUID.fromString(id);
    }
    
    public UUID getUuid()
    {
        return value;
    }

    @Override
    public boolean equals( Object obj )
    {
        if ( obj == null )
        {
            return false;
        }
        if ( getClass() != obj.getClass() )
        {
            return false;
        }
        final UniqueID other = (UniqueID) obj;
        if ( this.value != other.value && (this.value == null || !this.value.equals(other.value)) )
        {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode()
    {
        int hash = 3;
        hash = 19 * hash + (this.value != null ? this.value.hashCode() : 0);
        return hash;
    }
    
    
    public boolean isNonValue()
    {
        return  value.compareTo(EMPTY_UUID) == 0;
    }
    
    @Override
    public String toString()
    {
        return value.toString();
    }
}
